<table border=0 cellpadding="1px" cellspacing=0 width="100%">
<CFQUERY NAME="qryCLKLVCODE" DATASOURCE=#client.company_dsn#>
	SELECT WITHBALANCE, ALLOWNEGBALANCE
	FROM CLKLVCODE
	WHERE LEAVETYPE = '#Evaluate("GetEntry.LEAVETYPE")#'
</CFQUERY>

<CFIF NOT qryCLKLVCODE.RecordCount>
	<tr><td nowrap class="bold">Leave Type not found in Lookup table.</td></tr>
<CFELSEIF Trim(Ucase(qryCLKLVCODE.WITHBALANCE)) IS "N">
	<tr><td nowrap class="bold">Leave Type has unlimited balance.</td></tr>
	<CFSET lPreProcessValidated="Yes">
<CFELSE>
	<CFQUERY NAME="qryCINLVENTITLEMENT" DATASOURCE="#client.company_dsn#">
		SELECT LEAVEENTITLEMENT, TYPE, STARTDATE, ACCRUEDBALANCE, ACCRUEDBALANCEASOF,
				LEAVEBALANCE, LEAVEBALANCEASOF, AVAILEDLEAVE, AVAILEDLEAVEASOF, LEAVETYPE
		FROM CINLVENTITLEMENT
		WHERE PERSONNELIDNO = '#GetEntry.PERSONNELIDNO#' AND
			LEAVETYPE = '#Evaluate("GetEntry.LEAVETYPE")#'
	</CFQUERY>

	<CFIF qryCINLVENTITLEMENT.RecordCount>
		<CFQUERY NAME="qryCBR201" DATASOURCE=#client.company_dsn# MAXROWS=1>
			SELECT LEAVETRACKUNIT
			FROM CBR201
		</CFQUERY>

		<CFIF qryCBR201.RecordCount>
			<!--- Check workingdayscode --->
			<CFQUERY NAME="qryCMFPA" DATASOURCE="#client.company_dsn#">
				SELECT WORKINGDAYSCODE
				FROM CMFPA
				WHERE PERSONNELIDNO = '#GetEntry.PERSONNELIDNO#'
			</CFQUERY>

			<CFQUERY NAME="qryCLKWORKINGDAYS" DATASOURCE="#client.company_dsn#">
				SELECT WORKINGHOURSPDAY
				FROM CLKWORKINGDAYS
				WHERE WORKINGDAYSCODE = '#qryCMFPA.WORKINGDAYSCODE#'
			</CFQUERY>

			<CFIF qryCLKWORKINGDAYS.RecordCount>
				<!--- Check if noofhours exceed noofdays --->
				<CFSET nHoursInDays=DateDiff("d", Evaluate("GetEntry.STARTINGDATE"), Evaluate("GetEntry.ENDINGDATE"))>
				<CFSET nHoursApplied=Evaluate("GetEntry.LEAVEHOURS")>

				<CFIF nHoursInDays GTE 0>
					<CFSET nHoursInDays=nHoursInDays + 1>
				</CFIF>

				<CFIF nHoursApplied NEQ "" AND nHoursApplied NEQ 0>
					<CFIF Trim(LCase(qryCBR201.LEAVETRACKUNIT)) NEQ "by day">
						<CFSET nHoursInDays=nHoursInDays * qryCLKWORKINGDAYS.WORKINGHOURSPDAY>
					</CFIF>

					<CFIF nHoursApplied LTE nHoursInDays>
						<CFSET nLVHours=qryCINLVENTITLEMENT.LEAVEBALANCE>
						<CFSET nLVBalance=nLVHours - nHoursApplied>

						<CFOUTPUT>
						<tr>
							<td width="50%">
								<table border=0 cellpadding=2 cellspacing=0 width="100%">
								<tr>
									<td nowrap>Leave Type&nbsp;</td>
									<td nowrap width="100%" class="bold">#qryCINLVENTITLEMENT.LEAVETYPE#</td>
								</tr>
								<tr>
									<td nowrap>Leave Balance as of payroll cut-off&nbsp;</td>
									<td nowrap width="100%" class="bold">#qryCINLVENTITLEMENT.LEAVEBALANCE#</td>
								</tr>
								<tr>
									<td nowrap>Leave Balance as of&nbsp;</td>
									<td nowrap width="100%" class="bold">#DateFormat(qryCINLVENTITLEMENT.LEAVEBALANCEASOF, "mm/dd/yyyy")#</td>
								</tr>
								</table>
							</td>
							<td bgcolor="##808080"></td>
							<td width="50%">
								<table border=0 cellpadding=2 cellspacing=0 width="100%">
								<CFIF UCase(qryCINLVENTITLEMENT.TYPE) IS "EARNED">
									<tr>
										<td nowrap>&nbsp;Availed Leave&nbsp;</td>
										<td nowrap width="100%" class="bold">#qryCINLVENTITLEMENT.AVAILEDLEAVE#</td>
									</tr>
									<tr>
										<td nowrap>&nbsp;Availed Leave as of&nbsp;</td>
										<td nowrap width="100%" class="bold">#DateFormat(qryCINLVENTITLEMENT.AVAILEDLEAVEASOF, "mm/dd/yyyy")#</td>
									</tr>
								<CFELSE>
									<tr>
										<td nowrap>&nbsp;Accrued Balance&nbsp;</td>
										<td nowrap width="100%" class="bold">#qryCINLVENTITLEMENT.ACCRUEDBALANCE#</td>
									</tr>
									<tr>
										<td nowrap>&nbsp;Accrued Balance as of&nbsp;</td>
										<td nowrap width="100%" class="bold">#DateFormat(qryCINLVENTITLEMENT.ACCRUEDBALANCEASOF, "mm/dd/yyyy")#</td>
									</tr>
								</CFIF>
								<CFIF UCase(Evaluate("GetEntry.APPROVED")) NEQ "Y" OR UCase(Evaluate("GetEntry.APPROVED")) NEQ "C">
									<tr>
										<td nowrap>&nbsp;Leave Balance if Approved&nbsp;</td>
										<td nowrap width="100%" class="bold">
											#nLVBalance#
											<CFIF nLVBalance LT 0 AND qryCLKLVCODE.ALLOWNEGBALANCE NEQ "Y">
												(Negative Balance is not allowed)
											</CFIF>
										</td>
									</tr>
								</CFIF>
								</table>
							</td>
						</tr>

						<!--- Check if employee has enough leave balance --->
						<CFIF (nLVBalance GE 0) OR
							  (qryCLKLVCODE.ALLOWNEGBALANCE IS "Y")>
							<CFSET lPreProcessValidated="Yes">
						</CFIF>

						</CFOUTPUT>
					<CFELSE>
						<tr><td nowrap class="bold">No. of days/hours applied exceeds No. of days.</td></tr>
					</CFIF>
				<CFELSE>
					<tr><td nowrap class="bold">No. of days/hours applied is 0.</td></tr>
				</CFIF>
			<CFELSE>
				<tr><td nowrap class="bold">Invalid WORKINGDAYSCODE.</td></tr>
			</CFIF>
		<CFELSE>
			<tr><td nowrap class="bold">Leave Track Unit is not properly configured.</td></tr>
		</CFIF>
	<CFELSE>
		<tr><td nowrap class="bold">Leave Type not found in CINLVENTITLEMENT table.</td></tr>
	</CFIF>
</CFIF>
</table>
